import time

from Base.Base import Base
from selenium.webdriver.common.by import By

# 页面类
class Page1(Base):
    # 1.点击请登录
    login_loc = (By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def login(self):
        self.click(self.login_loc)
    # 断言5 会员登录
    dy5_loc = (By.XPATH, '/html/body/div[4]/div/div[1]/div[1]/span[1]')
    def dy5(self):
        return self.text(self.dy5_loc)
    # 2.输入用户名
    user_loc = (By.NAME, 'username')
    def user(self):
        self.send_keys(self.user_loc, '13811033962')
    # 3.输入密码
    pwd_loc = (By.NAME, 'password')
    def pwd(self):
        self.send_keys(self.pwd_loc, '123456')
    # 4.点击登录按钮
    login1_loc = (By.CSS_SELECTOR, '.finish-btn')
    def login1(self):
        self.click(self.login1_loc)
    # 断言6 登录成功
    dy6_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]')
    def dy6(self):
        return self.text(self.dy6_loc)
    # 5.点击首页
    home_loc = (By.XPATH, '/html/body/div[3]/div[2]/ul/li[1]/a')
    def home(self):
        self.click(self.home_loc)
    # 6.搜索输入并回车
    search_loc = (By.XPATH, '//input[@class="search-input" and @name="keywords"]')
    def search(self):
        self.send_keys(self.search_loc, '茅台')
        self.Enter(self.search_loc)
    # 7.点击商品进入商品详情页
    goods_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[1]/div[1]/span/a/img')
    def goods(self):
        self.click(self.goods_loc)
    # 断言7 茅台two
    dy7_loc = (By.XPATH, '/html/body/div[5]/div/div[2]/form/div/div[1]/span')
    def dy7(self):
        return self.text(self.dy7_loc)
    # 8.点击加人购物车
    add_loc=(By.ID,'add-cart')
    def add(self):
        self.click(self.add_loc)
    # 9.进入购物车页面
    join_loc=(By.CLASS_NAME,'nav-settcart')
    def join(self):
        self.click(self.join_loc)
    # 断言9 我的购物车
    dy9_loc=(By.XPATH,'/html/body/div[4]/div[1]/a[2]')
    def dy9(self):
        return self.text(self.dy9_loc)
    # 10.选择商品
    checkbox_loc=(By.XPATH,'/html/body/div[4]/form/div[1]/div[1]/table/tbody/tr[2]/td[1]/input')
    def checkbox(self):
        self.click(self.checkbox_loc)
    # 11.点击立即结算
    jiesuan_loc=(By.XPATH,'/html/body/div[4]/form/div[2]/div/a[2]')
    def jiesuan(self):
        self.click(self.jiesuan_loc)
    # 12.选择收货地址
    address_loc = (By.ID, 'address-802')
    def address(self):
        self.click(self.address_loc)
    # 13.点击下一步
    next_loc = (By.ID, 'order-button')
    def next(self):
        self.click(self.next_loc)
    # 断言8 订单完成
    dy8_loc = (By.XPATH, '/html/body/div[4]/div[1]/a[2]')
    def dy8(self):
        return self.text(self.dy8_loc)


    def luoji_a3mall_02_gwc_and_search(self):
        self.open_url('http://10.59.9.12:7001/')
        # 1.点击请登录
        self.login()
        # 断言5 会员登录
        print(self.dy5())
        assert "会员登录" == self.dy5()
        # 2.输入用户名
        self.user()
        # 3.输入密码
        self.pwd()
        # 强制等待输入验证码
        time.sleep(5)
        # 4.点击登录按钮
        self.login1()
        # 强制等待查看效果
        time.sleep(5)
        # 断言6 登录成功
        print(self.dy6())
        assert "您好，13811033962 欢迎回来！" in self.dy6()
        # 5.点击首页
        self.home()
        # 6.搜索输入并回车
        self.search()
        # 7.点击商品进入商品详情页
        self.goods()
        # 断言7 茅台two
        print(self.dy7())
        assert "茅台two" == self.dy7()
        # 8.点击加人购物车
        self.add()
        # 9.进入购物车页面
        self.join()
        # 强制等待看效果
        time.sleep(3)
        # 断言9 我的购物车
        print(self.dy9())
        assert "我的购物车" == self.dy9()
        # 10.选择商品
        self.checkbox()
        # 滚动
        self.handles()
        # 11.点击立即结算
        self.jiesuan()
        # 12.选择收货地址
        self.address()
        # 滚动
        self.handles()
        # 13.点击下一步
        self.next()
        time.sleep(3)
        # 断言8 订单完成
        print(self.dy8())
        assert "订单完成" == self.dy8()